﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Net;
using System.Xml;
using System.Text;
using System.IO;
namespace LHWebApp.Json
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class JsonGetVehicleCurrentInfoList : IHttpHandler
    {
        //houruixian 2018.07.13 
        List<CurrentVehicleEntity> currentVehicleList = new List<CurrentVehicleEntity>();
        CurrentVehicleEntity currentVehicle = null;

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string op = context.Request.Params["op"];
            switch (op)
            {
                //case "getStore":
                //    GetAlarmList(context);
                //    break;
                case "GetGroupList":
                    GetGroupList(context);
                    break;
                case "carListCurrentVehicle":
                    carListCurrentVehicle(context);
                    break;
                case "GetVideoLoginInfo":
                    getVideoLoginInfo(context);
                    break;
                case "GetVehicleCurrentInfoDistrict":
                    GetVehicleCurrentInfoDistrict(context);
                    break;
                case "GetVehicleCurrentInfoCity":
                    GetVehicleCurrentInfoCity(context);
                    break;
                case "GetVideoBySimcard_No":
                    GetVideoBySimcard_No(context);
                    break;
                case "GetVideoByLoaction":
                    GetVideoByLoaction(context);
                    break;

                case "GetPlaceCLC":
                    getPlaceCLC(context);
                    break;
                case "GetPlaceNCD":
                    getPlaceNCD(context);
                    break;
                case "GetPlaceZZZ":
                    getPlaceZZZ(context);
                    break;
                case "GetPlaceCY":
                    getPlaceCY(context);
                    break;
                case "GetPlaceXQCY":
                    getPlaceXQCY(context);
                    break;
                case "GetPlaceXQQT":
                    getPlaceXQQT(context);
                    break;
                default:
                    context.Response.Write("{success: false}");
                    break;
            }
        }
        private void GetVideoByLoaction(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string lng = context.Request.Params["lng"];
            string lat = context.Request.Params["lat"];
            //if (string.IsNullOrEmpty(carNum))
            //{
            //    context.Response.Write("{success: false}");
            //}
            //else
            //{
                try
                {
                    DataTable dt = LHWebApp.Services.GetVideoByLoaction(lng,lat).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("ICCID", dr[0].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            //}
        }
        private void GetVideoBySimcard_No(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string carNum = context.Request.Params["carNum"];
            if (string.IsNullOrEmpty(carNum))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVideoBySimcard_No(carNum).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("ICCID", dr[0].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        private void getVideoLoginInfo(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVideoLoginInfo(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("id", dr[0].ToString());
                            jsonHelp.AddItem("pword", dr[1].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        private void GetGroupList(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string currentService = context.Request.Params["currentService"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetClientInfoList(currentService, clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (currentService == "5") {
                                jsonHelp.AddItem("CLIENT_NAME", dr["CLIENT_NAME"].ToString());
                                jsonHelp.AddItem("CLIENT_NO", dr["CLIENT_NAME"].ToString());
                                jsonHelp.ItemOk();
                            }
                            else
                            {
                                jsonHelp.AddItem("CLIENT_NAME", dr["CLIENT_NAME"].ToString());
                                jsonHelp.AddItem("CLIENT_NO", dr["CLIENT_NO"].ToString());
                                jsonHelp.ItemOk();
                            }
                            
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }

        private void GetVehicleCurrentInfoCity(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string currentService = context.Request.Params["currentService"];

            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVehicleCurrentInfoCity(currentService, clientNo).Tables[0];//2019.09.20 zx

                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("type", dr[0].ToString());
                            jsonHelp.AddItem("carCountOnline", dr[1].ToString());
                            jsonHelp.AddItem("carCountAll", dr[2].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        private void GetVehicleCurrentInfoDistrict(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string currentService = context.Request.Params["currentService"];

            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVehicleCurrentInfoDistrict(currentService, clientNo).Tables[0];//2019.09.20 zx

                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("type", dr[0].ToString());
                            jsonHelp.AddItem("carCountOnline", dr[1].ToString());
                            jsonHelp.AddItem("carCountAll", dr[2].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        private void GetVehicleCurrentInfoSynthetical(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string tab = context.Request.Params["tab"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVehicleCurrentInfoSynthetical(clientNo, tab).Tables[0];//2019.09.20 zx

                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("type", dr[0].ToString());
                            jsonHelp.AddItem("carCountOnline", dr[1].ToString());
                            jsonHelp.AddItem("carCountAll", dr[2].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        private void carListCurrentVehicle(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string carType = context.Request.Params["carType"];//2018.07.23 houruixian 车辆类型
            string licensePlate = context.Request.Params["licensePlate"];//2019.09.20 zx 车辆牌号
            string carGroup = context.Request.Params["carGroup"];//2019.09.20 zx 车辆分组
            string carStatus = context.Request.Params["status"];//2019.09.20 zx 车辆状态
            string clientNo = context.Request.Params["clientNo"];

            string currentService = context.Request.Params["currentService"];

            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVehicleCurrentInfoList(currentService, clientNo, licensePlate, carGroup, carStatus, carType).Tables[0];//2019.09.20 zx

                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {

                        foreach (DataRow dr in dt.Rows)
                        {
                            currentVehicle = new CurrentVehicleEntity();
                            if (currentService == "6" || currentService == "5")
                            {
                                jsonHelp.AddItem("VID", dr["编号"].ToString());
                                jsonHelp.AddItem("ClientNo", dr["组织编号"].ToString());
                                jsonHelp.AddItem("ClientName", dr["组织名称"].ToString());
                                jsonHelp.AddItem("LicensePlate", dr["名称"].ToString());
                                jsonHelp.AddItem("CardNo", dr["通讯卡号"].ToString());

                                jsonHelp.AddItem("Lng", dr["经度"].ToString());
                                jsonHelp.AddItem("Lat", dr["纬度"].ToString());

                                jsonHelp.AddItem("Speed", dr["速度"].ToString());
                                jsonHelp.AddItem("Direction", dr["方向"].ToString());
                                jsonHelp.AddItem("GpsTime", dr["最终定位时间"].ToString());
                                jsonHelp.AddItem("CarType", dr["类型"].ToString());
                                
                                jsonHelp.AddItem("Location", dr["位置"].ToString());
                                //jsonHelp.AddItem("LngOffset", currentVehicleList[i].LngOffset);
                                //jsonHelp.AddItem("LatOffset", currentVehicleList[i].LatOffset);
                                //jsonHelp.AddItem("TemperatureRT", currentVehicleList[i].TemperatureRT);

                                jsonHelp.AddItem("ssection1", dr["性别"].ToString());
                                jsonHelp.AddItem("ssection2", dr["心跳"].ToString());
                                jsonHelp.AddItem("ssection3", dr["电话"].ToString());
                                jsonHelp.AddItem("ssection4", dr["所属清扫队"].ToString());
                                jsonHelp.AddItem("ssection5", dr["所属班组"].ToString());
                                jsonHelp.AddItem("ssection6", dr["负责区域"].ToString());
                                jsonHelp.AddItem("ssection7", dr["设备类型"].ToString());
                                jsonHelp.AddItem("ssection8", dr["打卡情况"].ToString());
                                jsonHelp.AddItem("ssection9", dr["油量"].ToString());
                                jsonHelp.AddItem("ssection10", dr["作业状态"].ToString());
                                jsonHelp.AddItem("ssection11", dr["扩展状态"].ToString());
                                jsonHelp.AddItem("ssection12", dr["指令应答"].ToString());
                                jsonHelp.AddItem("ssection13", dr["唯一标识码"].ToString());
                                jsonHelp.AddItem("ssection14", dr["生日"].ToString());
                                jsonHelp.AddItem("ssection15", dr["入职时间"].ToString());
                                

                                jsonHelp.AddItem("ssection4", dr["所属清扫队"].ToString());
                                jsonHelp.AddItem("ssection5", dr["所属班组"].ToString());
              
                                DateTime datetime = DateTime.ParseExact(dr["最终定位时间"].ToString(), "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                                TimeSpan difTime = DateTime.Now - datetime;
                                if (difTime.TotalMinutes > 3.0)
                                {
                                    jsonHelp.AddItem("Status", "6");
                                }
                                else
                                {
                                    jsonHelp.AddItem("Status", "0");
                                }

                                if (currentService == "5")
                                {
                                    jsonHelp.AddItem("ssection16", dr["数据类型"].ToString());
                                    jsonHelp.AddItem("LngOffset", dr["CurrentNum"].ToString());
                                    jsonHelp.AddItem("LatOffset", dr["ALLNUM"].ToString());
                                }
                                if (currentService == "6")
                                {
                                    jsonHelp.AddItem("LngOffset", dr["负责维保公厕"].ToString());
                                    jsonHelp.AddItem("LatOffset", dr["正在维保公厕"].ToString());
                                }

                                currentVehicle.Lng = dr["经度"].ToString();
                                currentVehicle.Lat = dr["纬度"].ToString();
                            }
                            else
                            {
                                jsonHelp.AddItem("VID", dr["VID"].ToString());
                                jsonHelp.AddItem("ClientNo", dr["ClientNo"].ToString());
                                jsonHelp.AddItem("ClientName", dr["ClientName"].ToString());
                                jsonHelp.AddItem("LicensePlate", dr["LicensePlate"].ToString());
                                jsonHelp.AddItem("CardNo", dr["CardNo"].ToString());

                                jsonHelp.AddItem("Lng", dr["Lng"].ToString());
                                jsonHelp.AddItem("Lat", dr["Lat"].ToString());

                                jsonHelp.AddItem("Speed", dr["Speed"].ToString());
                                jsonHelp.AddItem("Direction", dr["Direction"].ToString());
                                jsonHelp.AddItem("GpsTime", dr["GpsTime"].ToString());
                                jsonHelp.AddItem("CarType", dr["CarType"].ToString());
                                jsonHelp.AddItem("Status", dr["Status"].ToString());
                                jsonHelp.AddItem("Location", dr["Location"].ToString());
                                jsonHelp.AddItem("LngOffset", dr["CurrentNum"].ToString());
                                jsonHelp.AddItem("LatOffset", dr["ALLSUM"].ToString());
                                jsonHelp.AddItem("TemperatureRT", dr["TemperatureRT"].ToString());

                                if (currentService == "3")
                                {
                                    //jsonHelp.AddItem("ssection1", dr["转运时间"].ToString());
                                    //jsonHelp.AddItem("ssection2", dr["转运吨数"].ToString());
                                    //jsonHelp.AddItem("ssection3", dr["处理厂名称"].ToString());
                                    jsonHelp.AddItem("ssection1", "111");
                                    jsonHelp.AddItem("ssection2", "222");
                                    jsonHelp.AddItem("ssection3", "333");
                                }


                                currentVehicle.Lng = dr["Lng"].ToString();
                                currentVehicle.Lat = dr["Lat"].ToString();
                            }


                            currentVehicleList.Add(currentVehicle);
                            jsonHelp.ItemOk();

                        }
                        AdjustBaiduLongLat(currentVehicleList);
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }


        //2018.07.13 houruixian 百度地图经纬度矫正
        public void AdjustBaiduLongLat(List<CurrentVehicleEntity> lists)
        {
            int count = lists.Count / 100 + 1;
            string[] rawPoints = new string[count];
            for (int i = 0; i < count; i++)
            {
                rawPoints[i] = "";
            }
            List<CurrentVehicleEntity> currentLists = new List<CurrentVehicleEntity>();

            for (int i = 0; i < count; i++)
            {
                if (i < count - 1)
                {
                    for (int j = 0; j < 100; j++)
                    {
                        rawPoints[i] = rawPoints[i] + ";" + lists[j + i * 100].Lng + "," + lists[j + i * 100].Lat;
                    }
                }
                else
                {
                    for (int j = 0; j < lists.Count - 100 * (count - 1); j++)
                    {
                        rawPoints[i] = rawPoints[i] + ";" + lists[j + i * 100].Lng + "," + lists[j + i * 100].Lat;
                    }
                }
            }

            for (int i = 0; i < rawPoints.Length; i++)
            {
                rawPoints[i] = rawPoints[i].Substring(1, rawPoints[i].Length - 1);
            }

            for (int i = 0; i < count; i++)
            {
                currentLists = getBaiduLongLat(rawPoints[i]);
                if (i < count - 1)
                {
                    for (int j = 0; j < 100; j++)
                    {
                        currentVehicleList[j + i * 100].Lat = currentLists[j].Lat;
                        currentVehicleList[j + i * 100].Lng = currentLists[j].Lng;

                    }
                }
                else
                {
                    for (int j = 0; j < lists.Count - 100 * (count - 1); j++)
                    {
                        currentVehicleList[j + i * 100].Lat = currentLists[j].Lat;
                        currentVehicleList[j + i * 100].Lng = currentLists[j].Lng;
                    }
                }
            }

        }

        public List<CurrentVehicleEntity> getBaiduLongLat(string rawListStr)
        {
            List<CurrentVehicleEntity> currentLists = new List<CurrentVehicleEntity>();
            CurrentVehicleEntity currentEntity = null;

            string url = @"http://api.map.baidu.com/geoconv/v1/?coords=" + rawListStr + @"&from=1&to=5&ak=4HzsadCh4FDh1Eukq2shC3WT&output=xml";
            WebRequest request = WebRequest.Create(url);
            request.Method = "POST";
            XmlDocument xmlDoc = new XmlDocument();
            string sendData = xmlDoc.InnerXml;
            byte[] byteArray = Encoding.Default.GetBytes(sendData);

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response = request.GetResponse();
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream, System.Text.Encoding.GetEncoding("utf-8"));
            string responseXml = reader.ReadToEnd();

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(responseXml);
            string status = xml.DocumentElement.SelectSingleNode("status").InnerText;
            if (status == "0")
            {
                XmlNodeList pointnodes = xml.DocumentElement.GetElementsByTagName("point");

                foreach (XmlNode node in pointnodes)
                {
                    currentEntity = new CurrentVehicleEntity();
                    XmlNodeList XNodes = ((XmlElement)node).GetElementsByTagName("x");  //获取age子XmlElement集合  
                    if (XNodes.Count == 1)
                    {
                        currentEntity.Lng = XNodes[0].InnerText;
                    }
                    XmlNodeList YNodes = ((XmlElement)node).GetElementsByTagName("y");  //获取age子XmlElement集合  
                    if (YNodes.Count == 1)
                    {
                        currentEntity.Lat = YNodes[0].InnerText;
                    }

                    currentLists.Add(currentEntity);
                }
            }

            return currentLists;
        }


        //农村点
        private void getPlaceNCD(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.getPlaceNCD(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            //jsonHelp.AddItem("ID", dr[0].ToString());
                            jsonHelp.AddItem("Name", dr["POINTNAME"].ToString());
                            //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                            //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                            //jsonHelp.AddItem("TYPE", dr[3].ToString());
                            //jsonHelp.AddItem("SIZE", dr[4].ToString());
                            jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                            jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        //处理厂
        private void getPlaceCLC(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.getPlaceCLC(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            //jsonHelp.AddItem("ID", dr[0].ToString());
                            jsonHelp.AddItem("Name", dr["Name"].ToString());
                            //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                            //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                            //jsonHelp.AddItem("TYPE", dr[3].ToString());
                            //jsonHelp.AddItem("SIZE", dr[4].ToString());
                            jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                            jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        //中转站
        private void getPlaceXQQT(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.getPlaceXQQT(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            //jsonHelp.AddItem("ID", dr[0].ToString());
                            jsonHelp.AddItem("Name", dr["Name"].ToString());
                            //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                            //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                            //jsonHelp.AddItem("TYPE", dr[3].ToString());
                            //jsonHelp.AddItem("SIZE", dr[4].ToString());
                            jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                            jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        //中转站
        private void getPlaceZZZ(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.getPlaceZZZ(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            //jsonHelp.AddItem("ID", dr[0].ToString());
                            jsonHelp.AddItem("Name", dr["Name"].ToString());
                            //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                            //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                            //jsonHelp.AddItem("TYPE", dr[3].ToString());
                            //jsonHelp.AddItem("SIZE", dr[4].ToString());
                            jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                            jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        //餐饮
        private void getPlaceCY(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.getPlaceCY(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            //jsonHelp.AddItem("ID", dr[0].ToString());
                            jsonHelp.AddItem("Name", dr["Name"].ToString());
                            //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                            //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                            //jsonHelp.AddItem("TYPE", dr[3].ToString());
                            //jsonHelp.AddItem("SIZE", dr[4].ToString());
                            jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                            jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        //小区厨余
        private void getPlaceXQCY(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataTable dt = LHWebApp.Services.getPlaceXQCY(clientNo).Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //jsonHelp.AddItem("ID", dr[0].ToString());
                        jsonHelp.AddItem("Name", dr["Name"].ToString());
                        //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                        //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                        //jsonHelp.AddItem("TYPE", dr[3].ToString());
                        //jsonHelp.AddItem("SIZE", dr[4].ToString());
                        jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                        jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }
    }

}
